/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: ken
 * Date: 2024-02-03
 * Time: 21:04
 */
public class Test2 {
    public boolean hasCycle(ListNode head) {
        if(head == null) {
            return false;
        }
        ListNode fast = head;
        ListNode slow = head;

        while (fast != slow) {
            fast = fast.next.next;
            slow = slow.next;
            if(fast == null || fast.next == null) {
                return false;
            }
        }
        return true;
        }
}
